home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFBIND / AESCOMN.S < prev    next >
Text File  |  1993-03-26  |  6KB  |  153 lines

  1.  
  2. ;*========================================================================
  3. ;*
  4. ;* AESFAST Public Domain GEM bindings.
  5. ;*
  6. ;*    04/06/89    v1.2
  7. ;*                Added TST.W just before RTS in aes_return routine.    This
  8. ;*                hack keeps Laser C happy.  Laser has an optimization such
  9. ;*                that source code such as:
  10. ;*                   if (!rsrc_load(filename))
  11. ;*                        form_error(errno);
  12. ;*                Will generate assembler code like:
  13. ;*                   jsr     _rsrc_load
  14. ;*                   bne     ...
  15. ;*                So we have to make sure the CCR flags match the values in
  16. ;*                d0 upon return.  Returns through aes_do were working fine,
  17. ;*                but the extra tst instruction was needed in aes_return.
  18. ;*========================================================================
  19.  
  20. ;*************************************************************************
  21. ;*
  22. ;* AESCOMN - Common routines (takes the place of CRYSTAL).
  23. ;*
  24. ;*************************************************************************
  25.  
  26. ;-------------------------------------------------------------------------
  27. ; Define the offsets within the AES block storage area.
  28. ;-------------------------------------------------------------------------
  29.  
  30. aespb      =         0                    ; 'aespb' MUST be first!...
  31. pcontrl   =         0                    ;    Pointer to control array
  32. pglobal   =         4                    ;    Pointer to global array
  33. pintin      =         8                    ;    Pointer to intin array
  34. pintout   =        12                    ;    Pointer to intout array
  35. padrin      =        16                    ;    Pointer to adrin array
  36. padrout   =        20                    ;    Pointer to adrout array
  37.  
  38. control   =        24                    ; Control array is next...
  39. function  =        24                    ;    Function code
  40. sintin      =        26                    ;    size of intin
  41. sintout   =        28                    ;    size of intout
  42. sadrin      =        30                    ;    size of adrin
  43. sadrout   =        32                    ;    size of adrout
  44.  
  45. global      =        34                    ; Global array, needs no further def.
  46.  
  47.           globl    aesblock             ; export this
  48.           globl    _aespb                ; Export this label for C programs.
  49.           globl    _aescontrol            ; |v1.1: added
  50.           globl    _global                ; Export this label for C programs.
  51.           globl    _gl_apversion        ; |v1.1: added
  52.           globl    _gl_apid             ; Export this label for C programs.
  53.           globl    _gl_apcount            ; |v1.1: added
  54.           globl    _gl_apid             ; |v1.1: added
  55.           globl    _gl_apprivate        ; |v1.1: added
  56.           globl    _gl_apptree            ; |v1.1: added
  57.           globl    _gl_ap1resv            ; |v1.1: added
  58.           globl    _gl_aprshdr            ; |v1.8: added
  59.           globl    _gl_ap2resv            ; |v1.8: added
  60.  
  61.           globl    aes_do
  62.           globl    aes_call
  63.  
  64.           bss
  65.  
  66. aesblock:                                ; Integrated AES data block storage.
  67. _aespb:        ds.l      6                ;    Room for aespb array.
  68. _aescontrol:   ds.w      5                ;    Room for control array.
  69. _global:                                ;    Global array...
  70. _gl_apversion: ds.w      1                ;        AES version.
  71. _gl_apcount:   ds.w      1                ;        AES max appl count.
  72. _gl_apid:       ds.w      1                ;        Application id.
  73. _gl_apprivate: ds.l      1                ;        Application-specific data.
  74. _gl_apptree:   ds.l      1                ;        Pointer to head of RSC tree.
  75. _gl_ap1resv:                            ;|v1.4: (Old name retained)
  76. _gl_aprshdr:   ds.l      1                ;|v1.4: Pointer to rshdr struct.
  77. _gl_ap2resv:   ds.l      3                ;        Rest of the global array.
  78.  
  79.           text
  80.  
  81. ;-------------------------------------------------------------------------
  82. ; aes_do - Set up AESBLOCK call trap 2, return directly to caller in
  83. ;           program (do not go back to binding routine).
  84. ;
  85. ;           This routine is entered via 'jmp'.
  86. ;-------------------------------------------------------------------------
  87.  
  88. aes_do:
  89.           movem.l    d2/a2,-(sp)
  90.           subq.l    #2,sp                ; Allocate intout[1].
  91.           lea        aesblock,a2         ; Load pointer to AES block,
  92.           movep.l    d0,control+1(a2)    ; fill in the control array (!),
  93.           move.l    a1,pintin(a2)        ; store the intin ptr into aespb
  94.           move.l    a0,padrin(a2)        ; store the adrin ptr into aespb
  95.           move.l    sp,pintout(a2)        ; store the intout ptr into aespb
  96.           move.l    a2,d1                ; move the aespb pointer to the
  97.           move.w    #$C8,d0             ; interface register, also the AES
  98.           trap        #2                    ; function code, call AES.
  99.           move.w    (sp)+,d0            ; Return to caller with value from
  100.           movem.l    (sp)+,d2/a2         ; intout[0] in d0 (& CCR matches d0).
  101.           rts
  102.  
  103. ;-------------------------------------------------------------------------
  104. ; aes_return - Return values from the intout array (on the stack) to
  105. ;               the variables the caller gaves us pointers to, then
  106. ;               return directly to the caller of the binding.
  107. ;
  108. ;               This routine is entered via 'jmp'.
  109. ;-------------------------------------------------------------------------
  110.  
  111. aes_return:
  112.           move.w    0(a6,d1.w),d0        ; 1st...intout[0] always goes to d0.
  113. ret_loop:
  114.           addq.w    #2,d1                ; Increment intout offset,
  115.           beq.b     alldone             ; if zero, all return values done.
  116.           move.l    (a1)+,a0            ; Get pointer to return variable,
  117.           move.w    0(a6,d1.w),(a0)     ; move value from intout[n] to
  118.           bra.b     ret_loop            ; variable pointed to by call parms.
  119. alldone:
  120.           unlk        a6                    ; Undo the stack, & return intout[0]
  121.           tst.w     d0                    ; (insure CCR matches intout[0]) to
  122.           rts                            ; caller of the original binding.
  123.  
  124. ;-------------------------------------------------------------------------
  125. ; AES call - Set up AESBLOCK, call trap 2, return to binding routine that
  126. ;             called us.  That binding routine will probably do some little
  127. ;             cleanup or something, then want to exit via aes_return, above.
  128. ;             On exit from this routine, we will return a pointer to the
  129. ;             aes_return routine in a0, allowing the binding to do its thing
  130. ;             then get out via 'jmp (a0)', saving the need for a relocatable
  131. ;             reference to aes_return in the bindings.
  132. ;
  133. ;             This routine is entered via 'jsr'.
  134. ;-------------------------------------------------------------------------
  135.  
  136. aes_call:
  137.           movem.l    d2/a2,-(sp)
  138.           lea        aesblock,a2         ; Load pointer to AES block,
  139.           movep.l    d0,control+1(a2)    ; fill in the control array (!),
  140.           move.l    a1,pintin(a2)        ; store the intin ptr into aespb
  141.           move.l    a0,padrin(a2)        ; store the adrin ptr into aespb
  142.           add.l     a6,d1                ; build the intout ptr
  143.           move.l    d1,pintout(a2)        ; store it into aespb
  144.           move.l    a2,d1                ; move the aespb pointer to the
  145.           move.w    #$C8,d0             ; interface register, also the AES
  146.           trap        #2                    ; function code, call AES, return
  147.           lea        aes_return(pc),a0    ; a pointer to the return routine
  148.           movem.l    (sp)+,d2/a2         ; to the calling binding routine.
  149.           rts
  150.  
  151. ;          end of code
  152.  
  153.